//
//  UserBindingAccountController.m
//  CheekiOS
//
//  Created by mac on 2017/6/22.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserBindingAccountController.h"
#import "HSLimitText.h"

@interface UserBindingAccountController ()<HSLimitTextDelegate>
@property (nonatomic, strong) HSLimitText *accountText;
@property (nonatomic, strong) HSLimitText *NameText;
@property (nonatomic, strong) UserpersionlInfoModel *model;
@end

@implementation UserBindingAccountController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNavgationBarHiddenNo];
    

    self.title = @"绑定提现账户";
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 210)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    
    UILabel *accountLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 100, 50)];
    accountLab.text = @"支付宝账户";
    accountLab.font = FontP(15);
    accountLab.textColor = [UIColor blackColor];
    accountLab.textAlignment = NSTextAlignmentLeft;
    accountLab.backgroundColor = [UIColor whiteColor];
    [backView addSubview:accountLab];
    
    self.accountText = [[HSLimitText alloc] initWithFrame:CGRectMake(accountLab.right,0,KScreenWidth-accountLab.width,50) type:TextInputTypeTextfield];
    self.accountText.type =TextInputTypeTextfield;
    self.accountText.delegate = self;
    self.accountText.placeholder = @"请输入支付宝账户";
    self.accountText.isBecomFirstResponder = NO;
    
    [backView addSubview:self.accountText];
    
    UILabel *NameTextLab = [[UILabel alloc]initWithFrame:CGRectMake(15, accountLab.bottom, 100, 50)];
    NameTextLab.text = @"真实姓名";
    NameTextLab.font = FontP(15);
    NameTextLab.textColor = [UIColor blackColor];
    NameTextLab.backgroundColor = [UIColor whiteColor];
    NameTextLab.textAlignment = NSTextAlignmentLeft;

    [backView addSubview:NameTextLab];
    
    self.NameText = [[HSLimitText alloc] initWithFrame:CGRectMake(NameTextLab.right,self.accountText.bottom,KScreenWidth-NameTextLab.width,50) type:TextInputTypeTextfield];
    self.NameText.type =TextInputTypeTextfield;
    self.NameText.delegate = self;
    self.NameText.placeholder = @"请输入您的姓名";
    self.NameText.isBecomFirstResponder = NO;
    
    [backView addSubview:self.NameText];

    UILabel * lab = [UILabel new];
    lab.text = @"温馨提示";
    lab.font = FontP(15);
    lab.textColor = [UIColor blackColor];
    lab.frame = CGRectMake(15, self.NameText.bottom, KScreenWidth, 50);
    lab.backgroundColor = [UIColor whiteColor];
    [backView addSubview:lab];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, lab.bottom, KScreenWidth, 30)];
    label.text = @"1.填写真是的支付宝账户";
    label.font = FontP(12);
    label.textColor = ColorI(0x2e353f);
    label.backgroundColor = [UIColor whiteColor];

    [backView addSubview:label];
    
    UILabel *labelT = [[UILabel alloc]initWithFrame:CGRectMake(15, label.bottom, KScreenWidth, 30)];
    labelT.text = @"2.填写的姓名要与支付宝账户绑定信息保持一致";
    labelT.font = FontP(12);
    labelT.textColor = ColorI(0x2e353f);
    labelT.backgroundColor = [UIColor whiteColor];

    [backView addSubview:labelT];
    
    
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(25, labelT.bottom+153, KScreenWidth-50, 50);
    
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:@"提现" forState:UIControlStateNormal];
    btn.backgroundColor = Colorbackground;
    btn.layer.cornerRadius=25;
    btn.titleLabel.font = FontP(15);
    [btn addTarget:self action:@selector(commitClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:btn];
    
    
    [self requestDate];

}
- (void)requestDate{
    [HcardHttpmanager getPersionalInfosuccess:^(id sucess) {
        
        self.model = [UserpersionlInfoModel mj_objectWithKeyValues:sucess[@"res"]];
        if(self.model.zfb==nil||self.model.zfbName.length==0){
      

        }else{
            self.accountText.placeholder = _model.zfb;
            self.NameText.placeholder = _model.zfbName;
            self.accountText.textField.enabled = NO;
            self.NameText.textField.enabled = NO;

        }
        
    } failure:^(NSError *error) {
        
    }];
}
- (void)commitClick:(UIButton *)sender{

    if(self.accountText.text.length==0||self.NameText.text.length==0){
        [SVProgressHUD showInfoWithStatus:@"请输全信息!"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
    }
    else{
        NSDictionary *dict = @{
                               @"uid":[HQHttpManager getUserId],
                               @"zfbName":self.NameText.text,
                               @"zfb":self.accountText.text
                               };
        
        [HcardHttpmanager MakePersionalInfoWithParam:dict success:^(id sucess) {
            if(sucess){
                [SVProgressHUD showInfoWithStatus:@"绑定成功"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
                NSString *Str = @"UserBindingAccountNotification";
                [[NSNotificationCenter defaultCenter] postNotificationName:Str object:nil
                 ];
                [self.navigationController popViewControllerAnimated:YES];
            }
        } failure:^(NSError *error) {
            
        }];
        
    }
    
}


#pragma mark============= textFiled Delegate     ===========
- (void)limitTextLimitInput:(HSLimitText *)textLimitInput text:(NSString *)text
{
    if([textLimitInput isEqual:self.accountText]){
        self.accountText.text = text;
    }else{
        self.NameText.text = text;
    }
    
}

- (void)limitTextLimitInputOverStop:(HSLimitText *)textLimitInput
{
    NSLog(@"%@",@"超出什么都不做 直接截断");
}


@end
